package handlers

import (
	"content-show/models"

	"github.com/gin-gonic/gin"
)

func List(c *gin.Context) {
	var content []models.Content
	models.DB.Model(&models.Content{}).Find(&content)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": content,
	})
}
func Create(c *gin.Context) {
	title := c.PostForm("title")
	info := c.PostForm("info")
	if title == "" || info == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "不能为空",
		})
		return
	}
	data := models.Content{
		Title: title,
		Info:  info,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
}
